<template>
  <grid title="任务错误日志记录">
    <el-form inline
             style="width: 100%; text-align: left"
             label-width="60px"
             @submit.native.prevent="onSubmit"
             @reset.native.prevent="onReset"
             size="small">
      <el-form-item label="用户名">
        <el-input v-model="query.name"
                  placeholder="请输入用户名"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="IP"
                    label-width="50px">
        <el-input v-model="query.ip"
                  placeholder="例: 192.168.1.1"
                  clearable></el-input>
      </el-form-item>
      <el-form-item label="请求时间"
                    label-width="80px">
        <el-date-picker v-model="query.start_time"
                        class="modify-input"
                        type="datetime"
                        size="mini"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择开始日期">
        </el-date-picker>
        -
        <el-date-picker v-model="query.end_time"
                        class="modify-input"
                        type="datetime"
                        size="mini"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
                   native-type="submit">筛选</el-button>
        <el-button native-type="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list"
              border
              :resizable="false"
              stripe>
      <el-table-column type="index"
                       label="编号"
                       width="60"
                       align="center"></el-table-column>
      <el-table-column prop="name"
                       label="标签名">
      </el-table-column>
      <el-table-column prop="nums"
                       label="文章数">
        <template slot-scope="scope">
          <router-link :to="{
            name: 'topic',
            query: {
              tag: scope.row.id
            }
          }">
            <font color="#409EFF">{{scope.row.nums}}</font>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column prop="status"
                       label="状态">
        <template slot-scope="scope">
          <normal-status :data="scope.row"></normal-status>
        </template>
      </el-table-column>
      <el-table-column prop="created_at"
                       label="创建时间">
        <template slot-scope="scope">
          {{scope.row.created_at | timeFilter }}
        </template>
      </el-table-column>
      <el-table-column fixed="right"
                       label="操作"
                       width="240">
        <template slot-scope="scope">
          <el-button type="primary"
                     size="small"
                     icon="el-icon-edit"
                     @click="editRow(scope.row.id)"></el-button>
          <el-button type="danger"
                     @click="deleteRow(scope.row.id)"
                     size="small"
                     icon="el-icon-delete"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination layout="total, prev, pager, next"
                   background
                   @current-change="fetch"
                   :current-page.sync="query.page"
                   :page-size="query.limit"
                   hide-on-single-page
                   style="display: flex;justify-content: center;"
                   :total="task_total">
    </el-pagination>
  </grid>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import listMixin from '@/mixin/list'

export default {
  title: '任务错误日志记录',
  data () {
    return {
      query: {
        limit: 12,
        page: 1,
        name: undefined,
        ip: undefined,
        start_time: undefined,
        end_time: undefined
      }
    }
  },
  mixins: [listMixin],
  async asyncData ({ store, route }) {
    const { query } = route;
    return store.dispatch('log/fetchTaskList', { page: 1, limit: 12 })
  },
  computed: {
    ...mapGetters('log', ['task_list', 'task_total'])
  },
  methods: {
    ...mapActions('log', ['fetchTaskList']),
    fetchList (params) {
      return this.fetchTaskList(params)
    },
    fetch () {
      this.fetchTaskList(this.query)
    }
  }
}
</script>
